package app.purchase.a571xz.com.myandroidframe;

import com.facebook.stetho.Stetho;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.squareup.leakcanary.LeakCanary;
import com.umeng.analytics.MobclickAgent;

import app.purchase.a571xz.com.myandroidframe.base.BaseApplication;
import app.purchase.a571xz.com.myandroidframe.base.activity.ActivityLifeCallback;
import app.purchase.a571xz.com.myandroidframe.base.fragment.FragmentLifeCallback;

public class MyApplication extends BaseApplication {
    private static MyApplication myApplication = null;

    public static MyApplication getApplication() {
        return myApplication;
    }

    private ActivityLifeCallback activityLifeCallback;
    private FragmentLifeCallback fragmentLifeCallback;

    public FragmentLifeCallback getFragmentLifeCallback() {
        return fragmentLifeCallback;
    }

    public ActivityLifeCallback getActivityLifeCallback() {
        return activityLifeCallback;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        myApplication = this;
        activityLifeCallback = new ActivityLifeCallback();
        fragmentLifeCallback = new FragmentLifeCallback();

        registerActivityLifecycleCallbacks(activityLifeCallback);
        //Logger init
        Logger.addLogAdapter(new AndroidLogAdapter() {
            @Override
            public boolean isLoggable(int priority, String tag) {
                return BuildConfig.IS_DEBUG;
            }
        });

        if (BuildConfig.IS_DEBUG) {
            //调试开发工具facebook出品
            Stetho.initializeWithDefaults(this);
            //内存泄漏
            LeakCanary.install(this);
        }

        //友盟初始化
        MobclickAgent.setDebugMode(BuildConfig.IS_DEBUG);
        MobclickAgent.enableEncrypt(true);
    }

    @Override
    public void onTerminate() {
        //注销这个接口
        unregisterActivityLifecycleCallbacks(activityLifeCallback);
        super.onTerminate();
    }

}
